# Maintainer: Markus Rathgeb <maggu2810@gmail.com>

_realname=libserialport
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.2
pkgrel=1
pkgdesc="cross-platform library for accessing serial ports (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://sigrok.org/wiki/Libserialport"
license=('spdx:LGPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             'git')
source=("git+git://sigrok.org/libserialport#tag=${_realname}-${pkgver}")
sha256sums=('ee4570c5749c2fe47fd4b87f8b1ce3f162b84539432d68c886038c80d64922ba')

prepare(){
  cd "${srcdir}"/${_realname}
  ./autogen.sh
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-shared \
    --enable-static

  make
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}
  PATH="${srcdir}/build-${MSYSTEM}/src/.libs:$PATH" make check || true
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}"/${_realname}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
